package com_.dxy_test_.diy_tomcat_;

import java.io.IOException;

/**
 * @Description 自定义Servlet积累，各个处理不用业务的servlet都继承此基类
 *
 * Tomcat是一款Servlet规范的web容器，提供了包括Socket服务、请求分发、封装请求和响应的功能
 * @Author dangxianyue
 * @Date 2022/9/26 15:34
 */
public abstract class MyServlet {

    protected abstract void doGet(MyRequest request, MyResponse response) throws IOException;

    protected abstract void doPost(MyRequest request, MyResponse response) throws IOException;

    public void service(MyRequest request, MyResponse response) throws IOException {
        String method = request.getMethod();
        if ("GET".equalsIgnoreCase(method)) {
            doGet(request, response);
        } else if ("POST".equalsIgnoreCase(method)) {
            doPost(request, response);
        } else {
            throw new IllegalArgumentException("不支持的请求类型！");
        }
    }

}
